package cn.wolfcode.trip.base.domain;

import com.alibaba.fastjson.JSON;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Getter;
import lombok.Setter;
import org.springframework.format.annotation.DateTimeFormat;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

@Getter
@Setter
/**
 *结伴相关信息
 */
public class Together extends BaseDomain {
    public static final Integer STATE_COMMON = 0;//草稿
    public static final Integer STATE_AUDIT = 1;//待审核
    public static final Integer STATE_RELEASE = 2;//已发布
    public static final Integer STATE_REJECT = -1;//已拒绝


    private String title;//标题
    @JsonFormat(pattern = "yyyy/MM/dd/ ", timezone = "GMT+8")
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date travelTime;//出行时间

    private String perExpends;//人均消费

    private Integer days;//出行天数

    private Integer person = 1;//出行人数

    private User author;//作者id
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Date createTime;//创建时间
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Date releaseTime;//发布时间

    private Region place;//出行地区

    private String coverUrl;//文本背景

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Date lastUpdateTime;//更新时间

    private Integer state = STATE_COMMON;//默认草稿状态   '//'

    private String content;//结伴说明



    //点击浏览量
    private int browseNum = 0;

    //评论数量
    private int commentNum;

    public String getStateName() {

        switch (state) {
            case 1:
                return "待审核";
            case 2:
                return "已发布";
            case -1:
                return "已拒绝";
        }
        return "草稿";
    }

    public String getPersons() {
        if (person != null) {
            switch (person) {
                case 1:
                    return "2个人";
                case 2:
                    return "3个人";
                case 3:
                    return "4个人";
                case 4:
                    return "5个人";

            }
        }
        return "5个以上";
    }

    public String getJson() {
        //共享给按钮的json数据
        Map<String, Object> map = new HashMap<>();
        map.put("id", id);
        map.put("title", title);
        map.put("coverUrl", coverUrl);
        return JSON.toJSONString(map);
    }

}